<?php
class BaseProperty extends Zend_Db_Table
{   
    protected $_name = "property";
    
    /**
    * Class constructor
    * @return void
    */    
	function __construct($config = null){
        parent::__construct();
        
        
        $this->id = 0;
        
        $this->type = 0;
        
        $this->name_vi = "";
        
        $this->name_en = "";
        
        $this->short_description_en = "";
        
        $this->short_description_vi = "";
        
        $this->description_en = "";
        
        $this->description_vi = "";
        
        $this->city = 0;
        
        $this->state_en = "";
        
        $this->state_vi = "";
        
        $this->street_en = "";
        
        $this->street_vi = "";
        
        $this->area = "";
        
        $this->price = "";
        
        $this->created = date("Y-m-d H:i:s");
        
        $this->status = 0;
        
        $this->image = "";
        
        $this->website = "";
        
        $this->contact_phone = "";
        
        $this->contact_email = "";
        
    }
	
    function clearData()
    {
        
        $this->id = 0;
        
        $this->type = 0;
        
        $this->name_vi = "";
        
        $this->name_en = "";
        
        $this->short_description_en = "";
        
        $this->short_description_vi = "";
        
        $this->description_en = "";
        
        $this->description_vi = "";
        
        $this->city = 0;
        
        $this->state_en = "";
        
        $this->state_vi = "";
        
        $this->street_en = "";
        
        $this->street_vi = "";
        
        $this->area = "";
        
        $this->price = "";
        
        $this->created = date("Y-m-d H:i:s");
        
        $this->status = 0;
        
        $this->image = "";
        
        $this->website = "";
        
        $this->contact_phone = "";
        
        $this->contact_email = "";
        
    }
    
	/**
	All property of class
	*/
    
    /*
	* @declare   id of  Property
	*/
    protected $id;
    
    /*
	* @declare   type of  Property
	*/
    protected $type;
    
    /*
	* @declare   name_vi of  Property
	*/
    protected $name_vi;
    
    /*
	* @declare   name_en of  Property
	*/
    protected $name_en;
    
    /*
	* @declare   short_description_en of  Property
	*/
    protected $short_description_en;
    
    /*
	* @declare   short_description_vi of  Property
	*/
    protected $short_description_vi;
    
    /*
	* @declare   description_en of  Property
	*/
    protected $description_en;
    
    /*
	* @declare   description_vi of  Property
	*/
    protected $description_vi;
    
    /*
	* @declare   city of  Property
	*/
    protected $city;
    
    /*
	* @declare   state_en of  Property
	*/
    protected $state_en;
    
    /*
	* @declare   state_vi of  Property
	*/
    protected $state_vi;
    
    /*
	* @declare   street_en of  Property
	*/
    protected $street_en;
    
    /*
	* @declare   street_vi of  Property
	*/
    protected $street_vi;
    
    /*
	* @declare   area of  Property
	*/
    protected $area;
    
    /*
	* @declare   price of  Property
	*/
    protected $price;
    
    /*
	* @declare   created of  Property
	*/
    protected $created;
    
    /*
	* @declare   status of  Property
	*/
    protected $status;
    
    /*
	* @declare   image of  Property
	*/
    protected $image;
    
    /*
	* @declare   website of  Property
	*/
    protected $website;
    
    /*
	* @declare   contact_phone of  Property
	*/
    protected $contact_phone;
    
    /*
	* @declare   contact_email of  Property
	*/
    protected $contact_email;
    
    
    /**
        All method of Property
    */
    
    /**
     * @desc this method will set the value of the $id property
     * @param int  $id
     * @return void
     */
     function setId($id)
     {
        $this->id = $id;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $id property 
     * @param void
     * @return int of $id
     */
     function getId()
     {
        return  $this->id;
     } // end get function
     
    /**
     * @desc this method will set the value of the $type property
     * @param int  $type
     * @return void
     */
     function setType($type)
     {
        $this->type = $type;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $type property 
     * @param void
     * @return int of $type
     */
     function getType()
     {
        return  $this->type;
     } // end get function
     
    /**
     * @desc this method will set the value of the $name_vi property
     * @param varchar  $name_vi
     * @return void
     */
     function setNameVi($name_vi)
     {
        $this->name_vi = $name_vi;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $name_vi property 
     * @param void
     * @return varchar of $name_vi
     */
     function getNameVi()
     {
        return  $this->name_vi;
     } // end get function
     
    /**
     * @desc this method will set the value of the $name_en property
     * @param varchar  $name_en
     * @return void
     */
     function setNameEn($name_en)
     {
        $this->name_en = $name_en;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $name_en property 
     * @param void
     * @return varchar of $name_en
     */
     function getNameEn()
     {
        return  $this->name_en;
     } // end get function
     
    /**
     * @desc this method will set the value of the $short_description_en property
     * @param mediumtext  $short_description_en
     * @return void
     */
     function setShortDescriptionEn($short_description_en)
     {
        $this->short_description_en = $short_description_en;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $short_description_en property 
     * @param void
     * @return mediumtext of $short_description_en
     */
     function getShortDescriptionEn()
     {
        return  $this->short_description_en;
     } // end get function
     
    /**
     * @desc this method will set the value of the $short_description_vi property
     * @param mediumtext  $short_description_vi
     * @return void
     */
     function setShortDescriptionVi($short_description_vi)
     {
        $this->short_description_vi = $short_description_vi;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $short_description_vi property 
     * @param void
     * @return mediumtext of $short_description_vi
     */
     function getShortDescriptionVi()
     {
        return  $this->short_description_vi;
     } // end get function
     
    /**
     * @desc this method will set the value of the $description_en property
     * @param mediumtext  $description_en
     * @return void
     */
     function setDescriptionEn($description_en)
     {
        $this->description_en = $description_en;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $description_en property 
     * @param void
     * @return mediumtext of $description_en
     */
     function getDescriptionEn()
     {
        return  $this->description_en;
     } // end get function
     
    /**
     * @desc this method will set the value of the $description_vi property
     * @param mediumtext  $description_vi
     * @return void
     */
     function setDescriptionVi($description_vi)
     {
        $this->description_vi = $description_vi;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $description_vi property 
     * @param void
     * @return mediumtext of $description_vi
     */
     function getDescriptionVi()
     {
        return  $this->description_vi;
     } // end get function
     
    /**
     * @desc this method will set the value of the $city property
     * @param int  $city
     * @return void
     */
     function setCity($city)
     {
        $this->city = $city;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $city property 
     * @param void
     * @return int of $city
     */
     function getCity()
     {
        return  $this->city;
     } // end get function
     
    /**
     * @desc this method will set the value of the $state_en property
     * @param varchar  $state_en
     * @return void
     */
     function setStateEn($state_en)
     {
        $this->state_en = $state_en;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $state_en property 
     * @param void
     * @return varchar of $state_en
     */
     function getStateEn()
     {
        return  $this->state_en;
     } // end get function
     
    /**
     * @desc this method will set the value of the $state_vi property
     * @param varchar  $state_vi
     * @return void
     */
     function setStateVi($state_vi)
     {
        $this->state_vi = $state_vi;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $state_vi property 
     * @param void
     * @return varchar of $state_vi
     */
     function getStateVi()
     {
        return  $this->state_vi;
     } // end get function
     
    /**
     * @desc this method will set the value of the $street_en property
     * @param varchar  $street_en
     * @return void
     */
     function setStreetEn($street_en)
     {
        $this->street_en = $street_en;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $street_en property 
     * @param void
     * @return varchar of $street_en
     */
     function getStreetEn()
     {
        return  $this->street_en;
     } // end get function
     
    /**
     * @desc this method will set the value of the $street_vi property
     * @param varchar  $street_vi
     * @return void
     */
     function setStreetVi($street_vi)
     {
        $this->street_vi = $street_vi;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $street_vi property 
     * @param void
     * @return varchar of $street_vi
     */
     function getStreetVi()
     {
        return  $this->street_vi;
     } // end get function
     
    /**
     * @desc this method will set the value of the $area property
     * @param double  $area
     * @return void
     */
     function setArea($area)
     {
        $this->area = $area;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $area property 
     * @param void
     * @return double of $area
     */
     function getArea()
     {
        return  $this->area;
     } // end get function
     
    /**
     * @desc this method will set the value of the $price property
     * @param double  $price
     * @return void
     */
     function setPrice($price)
     {
        $this->price = $price;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $price property 
     * @param void
     * @return double of $price
     */
     function getPrice()
     {
        return  $this->price;
     } // end get function
     
    /**
     * @desc this method will set the value of the $created property
     * @param datetime  $created
     * @return void
     */
     function setCreated($created)
     {
        $this->created = $created;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $created property 
     * @param void
     * @return datetime of $created
     */
     function getCreated()
     {
        return  $this->created;
     } // end get function
     
    /**
     * @desc this method will set the value of the $status property
     * @param int  $status
     * @return void
     */
     function setStatus($status)
     {
        $this->status = $status;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $status property 
     * @param void
     * @return int of $status
     */
     function getStatus()
     {
        return  $this->status;
     } // end get function
     
    /**
     * @desc this method will set the value of the $image property
     * @param varchar  $image
     * @return void
     */
     function setImage($image)
     {
        $this->image = $image;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $image property 
     * @param void
     * @return varchar of $image
     */
     function getImage()
     {
        return  $this->image;
     } // end get function
     
    /**
     * @desc this method will set the value of the $website property
     * @param varchar  $website
     * @return void
     */
     function setWebsite($website)
     {
        $this->website = $website;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $website property 
     * @param void
     * @return varchar of $website
     */
     function getWebsite()
     {
        return  $this->website;
     } // end get function
     
    /**
     * @desc this method will set the value of the $contact_phone property
     * @param varchar  $contact_phone
     * @return void
     */
     function setContactPhone($contact_phone)
     {
        $this->contact_phone = $contact_phone;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $contact_phone property 
     * @param void
     * @return varchar of $contact_phone
     */
     function getContactPhone()
     {
        return  $this->contact_phone;
     } // end get function
     
    /**
     * @desc this method will set the value of the $contact_email property
     * @param varchar  $contact_email
     * @return void
     */
     function setContactEmail($contact_email)
     {
        $this->contact_email = $contact_email;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $contact_email property 
     * @param void
     * @return varchar of $contact_email
     */
     function getContactEmail()
     {
        return  $this->contact_email;
     } // end get function
       
     
     
     /**
     * @desc this function get Property  by $id
     * @var int : $id 
     * @var 
     * @return Property object
     */
     function getById($id)
     {
          $row = $this->fetchRow("id='$id'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $type
     * @var int : $type 
     * @var 
     * @return Property object
     */
     function getByType($type)
     {
          $row = $this->fetchRow("type='$type'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $name_vi
     * @var varchar : $name_vi 
     * @var 
     * @return Property object
     */
     function getByNameVi($name_vi)
     {
          $row = $this->fetchRow("name_vi='$name_vi'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $name_en
     * @var varchar : $name_en 
     * @var 
     * @return Property object
     */
     function getByNameEn($name_en)
     {
          $row = $this->fetchRow("name_en='$name_en'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $short_description_en
     * @var mediumtext : $short_description_en 
     * @var 
     * @return Property object
     */
     function getByShortDescriptionEn($short_description_en)
     {
          $row = $this->fetchRow("short_description_en='$short_description_en'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $short_description_vi
     * @var mediumtext : $short_description_vi 
     * @var 
     * @return Property object
     */
     function getByShortDescriptionVi($short_description_vi)
     {
          $row = $this->fetchRow("short_description_vi='$short_description_vi'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $description_en
     * @var mediumtext : $description_en 
     * @var 
     * @return Property object
     */
     function getByDescriptionEn($description_en)
     {
          $row = $this->fetchRow("description_en='$description_en'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $description_vi
     * @var mediumtext : $description_vi 
     * @var 
     * @return Property object
     */
     function getByDescriptionVi($description_vi)
     {
          $row = $this->fetchRow("description_vi='$description_vi'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $city
     * @var int : $city 
     * @var 
     * @return Property object
     */
     function getByCity($city)
     {
          $row = $this->fetchRow("city='$city'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $state_en
     * @var varchar : $state_en 
     * @var 
     * @return Property object
     */
     function getByStateEn($state_en)
     {
          $row = $this->fetchRow("state_en='$state_en'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $state_vi
     * @var varchar : $state_vi 
     * @var 
     * @return Property object
     */
     function getByStateVi($state_vi)
     {
          $row = $this->fetchRow("state_vi='$state_vi'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $street_en
     * @var varchar : $street_en 
     * @var 
     * @return Property object
     */
     function getByStreetEn($street_en)
     {
          $row = $this->fetchRow("street_en='$street_en'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $street_vi
     * @var varchar : $street_vi 
     * @var 
     * @return Property object
     */
     function getByStreetVi($street_vi)
     {
          $row = $this->fetchRow("street_vi='$street_vi'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $area
     * @var double : $area 
     * @var 
     * @return Property object
     */
     function getByArea($area)
     {
          $row = $this->fetchRow("area='$area'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $price
     * @var double : $price 
     * @var 
     * @return Property object
     */
     function getByPrice($price)
     {
          $row = $this->fetchRow("price='$price'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $created
     * @var datetime : $created 
     * @var 
     * @return Property object
     */
     function getByCreated($created)
     {
          $row = $this->fetchRow("created='$created'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $status
     * @var int : $status 
     * @var 
     * @return Property object
     */
     function getByStatus($status)
     {
          $row = $this->fetchRow("status='$status'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $image
     * @var varchar : $image 
     * @var 
     * @return Property object
     */
     function getByImage($image)
     {
          $row = $this->fetchRow("image='$image'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $website
     * @var varchar : $website 
     * @var 
     * @return Property object
     */
     function getByWebsite($website)
     {
          $row = $this->fetchRow("website='$website'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $contact_phone
     * @var varchar : $contact_phone 
     * @var 
     * @return Property object
     */
     function getByContactPhone($contact_phone)
     {
          $row = $this->fetchRow("contact_phone='$contact_phone'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Property  by $contact_email
     * @var varchar : $contact_email 
     * @var 
     * @return Property object
     */
     function getByContactEmail($contact_email)
     {
          $row = $this->fetchRow("contact_email='$contact_email'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
       
     
     // function save ".trimplural($table)." 
     public function save($forceInsert= false)
     { 
         if( $forceInsert == true)
            return $this->insert($this->toArray());
         $update = false;
         $condition = array(); 
        
        if($this->getId())
        {
            // is update
            $update = true;
            $condition[] = "id ='". $this->getId() ."'";
        }
        
         if( $update )   // update Property
         {
            return $this->update($this->toArray(),implode(" and ",$condition));
         }
         else
         {
             $this->insert($this->toArray());
         }
     }
     /**
     * @desc this function get list of ".$table."
     * @var int : string $where condition, $page is current page, $rowCount is total row
     * @var 
     * @return user object
     */
     public function getListProperty($where = null,$order = array(),$page = null ,$rowCount = null)
     {
        $select =  $this->select();
        if($where != null)
            $select->where($where);
         if($page===null)
             $select->from($this->_name);
        else
           $select->from($this->_name)->limitPage($page,$rowCount);
        $select->order($order);
        return $this->fetchAll($select);
     }     
     
     /**
     * @desc this method will import data from array 
     * @param void
     * @return array
     */
     function fromArray($array)
     {
        // import all proper ty
        
        if(isset($array["id"]))
                $this->id = $array["id"];
        
        if(isset($array["type"]))
                $this->type = $array["type"];
        
        if(isset($array["name_vi"]))
                $this->name_vi = $array["name_vi"];
        
        if(isset($array["name_en"]))
                $this->name_en = $array["name_en"];
        
        if(isset($array["short_description_en"]))
                $this->short_description_en = $array["short_description_en"];
        
        if(isset($array["short_description_vi"]))
                $this->short_description_vi = $array["short_description_vi"];
        
        if(isset($array["description_en"]))
                $this->description_en = $array["description_en"];
        
        if(isset($array["description_vi"]))
                $this->description_vi = $array["description_vi"];
        
        if(isset($array["city"]))
                $this->city = $array["city"];
        
        if(isset($array["state_en"]))
                $this->state_en = $array["state_en"];
        
        if(isset($array["state_vi"]))
                $this->state_vi = $array["state_vi"];
        
        if(isset($array["street_en"]))
                $this->street_en = $array["street_en"];
        
        if(isset($array["street_vi"]))
                $this->street_vi = $array["street_vi"];
        
        if(isset($array["area"]))
                $this->area = $array["area"];
        
        if(isset($array["price"]))
                $this->price = $array["price"];
        
        if(isset($array["created"]))
                $this->created = $array["created"];
        
        if(isset($array["status"]))
                $this->status = $array["status"];
        
        if(isset($array["image"]))
                $this->image = $array["image"];
        
        if(isset($array["website"]))
                $this->website = $array["website"];
        
        if(isset($array["contact_phone"]))
                $this->contact_phone = $array["contact_phone"];
        
        if(isset($array["contact_email"]))
                $this->contact_email = $array["contact_email"];
        
        // return object
        return $this;
     } // end export function
     
     /**
     * @desc this method will export data to array 
     * @param void
     * @return array
     */
     function toArray()
     {
        // import all proper ty
        $array = array();
        
        $array["id"] = $this->id;
        
        $array["type"] = $this->type;
        
        $array["name_vi"] = $this->name_vi;
        
        $array["name_en"] = $this->name_en;
        
        $array["short_description_en"] = $this->short_description_en;
        
        $array["short_description_vi"] = $this->short_description_vi;
        
        $array["description_en"] = $this->description_en;
        
        $array["description_vi"] = $this->description_vi;
        
        $array["city"] = $this->city;
        
        $array["state_en"] = $this->state_en;
        
        $array["state_vi"] = $this->state_vi;
        
        $array["street_en"] = $this->street_en;
        
        $array["street_vi"] = $this->street_vi;
        
        $array["area"] = $this->area;
        
        $array["price"] = $this->price;
        
        $array["created"] = $this->created;
        
        $array["status"] = $this->status;
        
        $array["image"] = $this->image;
        
        $array["website"] = $this->website;
        
        $array["contact_phone"] = $this->contact_phone;
        
        $array["contact_email"] = $this->contact_email;
        
        // return object
        return $array;
     } // end export function
     
    function numRows($where = null)
    {
        $select = $this->_db->select();
        $select->from($this->_name, "COUNT(*)", $this->_schema);
        // the WHERE clause
        $where = (array) $where;
        foreach ($where as $key => $val) {
            // is $key an int?
            if (is_int($key)) {
                // $val is the full condition
                $select->where($val);
            } else {
                // $key is the condition with placeholder,
                // and $val is quoted into the condition              
                $select->where($key, $val);           
            }          
        }
        // return the results
        $stmt = $this->_db->query($select);
        
        $data = $stmt->fetchColumn(0);       
        return $data;  
    }              
}